package com.nc.user.dao;

import com.nc.user.model.entity.FrmPermissions;
import com.nc.user.model.entity.FrmRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Set;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
public interface FrmPermissionsDao extends JpaRepository<FrmPermissions, String> {
    List<FrmPermissions> findByCodeIn(Set<String> codes);

    @Modifying
    @Query(value = "SELECT a.* FROM frm_permissions AS a JOIN frm_role_permissions_role AS b " +
            "ON a.id = b.permissions_role_id JOIN frm_role as c on b.frm_role_id = c.id " +
            "WHERE c.`code` in (:roles)", nativeQuery = true)
    List<FrmPermissions> findByFrmRolesCode(List<String> roles);
}
